// hyb_yl/krecovery/pages/guide/guide.js
var minuteList = [];
var weekList = [];
var app = getApp();
for (var i = 1; i < 61; i++) {
  if (i < 10) {
    minuteList.push('0' + i)
  } else {
    minuteList.push(i)
  }
}
for (var i = 1; i < 8; i++) {
  if (i < 10) {
    weekList.push('0' + i)
  } else {
    weekList.push(i)
  }
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page_state:1,
    keshiList:['急诊科','肛肠科'],
    date: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
    numlist: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
    minuteList: minuteList,
    weekList: weekList,
    back_orser:"",
    openid:"",
    names:"",
    sex:"",
    age:"",
    tel:"",
    address:"",
    zy_time:"",
    cy_time:"",
    keshi:"",
    roomid:"",
    content:"",
    other_content:"",
    fc_time:"",
    xy_content:"",
    xt_content:"",
    xl_content:"",
    xb_content:"",
    wb_content:"",
    ns_content:"",
    sleep_content:"",
    tx_content:"",
    zid:"",
    j_id:"",
    xy_am_time:1,
    xy_am_number:1,
    xy_pm_time:1,
    xy_pm_number:1,
    jz_time:1,
    xt_am_time:1,
    xt_am_number:1,
    am_xt_title:1,
    xt_pm_time:1,
    xt_pm_number:1,
    pm_xt_title:"",
    xl_am_time:1,
    xb_am_time:1,
    wb_am_time:1,
    ns_am_time:1,
    ns_am_number:1,
    wb_am_number:1,
    xb_am_number:1,
    xl_am_number:1,
    xl_pm_time:1,
    xl_pm_number:1,
    xb_pm_time:1,
    xb_pm_number:1,
    wb_pm_number:1,
    wb_pm_time:1,
    ns_pm_time:1,
    ns_pm_number:1,
    ns_pm_day:1,
    sleep_month:1,
    sleep_week:1,
    sleep_time:1,
    sleep_number:1,
    tx_number:1,
    tx_week:1,
    tx_month:1,
  },
  // 血糖测量
  am_can_choose: function (e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      am_can_index: index,
      am_xt_index:index,
    })
    if(index == 1)
    {
      this.setData({
        am_xt_title:"餐前"
      })
    }else{
      this.setData({
        am_xt_title:"餐后"
      })
    }
  },
  // 血糖测量
  pm_can_choose: function (e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      pm_can_index: index,
      pm_xt_index:index
    })
    if(index == 1)
    {
      this.setData({
        pm_xt_title:"餐前"
      })
    }else{
      this.setData({
        pm_xt_title:"餐后"
      })
    }
  },
  // 血压上午检测
  am_xy_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      xy_am_time:time+1,
      xy_am_number:val+1
    })
  },

  // 血压下午检测
  pm_xy_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      xy_pm_time:time+1,
      xy_pm_number:val+1
    })
  },
  // 测量前静置
  bindChange:function(e){
    var time = e.detail.value;
    this.setData({
      jz_time:time+1
    })
  },
  // 血糖上午检测
  am_xt_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      xt_am_time:time+1,
      xt_am_number:val+1
    })
  },

  // 血糖下午检测
  pm_xt_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      xt_pm_time:time+1,
      xt_pm_number:val+1
    })
  },
   // 心率上午检测
   am_xl_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      xl_am_time:time+1,
      xl_am_number:val+1
    })
  },

  // 心率下午检测
  pm_xl_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      xl_pm_time:time+1,
      xl_pm_number:val+1
    })
  },
  // 血氧上午检测
  am_xb_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      xb_am_time:time+1,
      xb_am_number:val+1
    })
  },

  // 血氧下午检测
  pm_xb_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      xb_pm_time:time+1,
      xb_pm_number:val+1
    })
  },
  // 腕表上午检测
  am_wb_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      wb_am_time:time+1,
      wb_am_number:val+1
    })
  },

  // 腕表下午检测
  pm_xy_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      wb_pm_time:time+1,
      wb_pm_number:val+1
    })
  },
  // 尿酸上午检测
  am_ns_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      ns_am_time:time+1,
      ns_am_number:val+1
    })
  },

  // 尿酸下午检测
  pm_ns_choose: function (e) {
    const time = e.detail.value[0];
    var val = e.detail.value[1]
    this.setData({
      ns_pm_time:time+1,
      ns_pm_number:val+1,
      ns_pm_day:e.detail.value[2]+1
    })
  },

  
  // 睡眠检测
  am_sleep_choose:function(e){
    var month = e.detail.value[0];
    var week = e.detail.value[1];
    var time = e.detail.value[2];
    var number = e.detail.value[3];
    this.setData({
      sleep_month:month+1,
      sleep_week:week+1,
      sleep_time:time+1,
      sleep_number:number+1
    })
  },
   
  // 胎心检测
  am_tx_choose:function(e){
    var month = e.detail.value[0];
    var week = e.detail.value[1];
    var number = e.detail.value[2];
    this.setData({
      tx_month:month+1,
      tx_week:week+1,
      tx_number:number+1
    })
  },
  // 基本信息下一步
  user_info: function (e) {
    console.log(e.detail.value);
    var val = e.detail.value;
    if(val.names==''){
      wx.showToast({
        title: '请输入患者姓名',
        icon:"none"
      })
    }else if(val.age==''){
      wx.showToast({
        title: '请输入患者年龄',
        icon:"none"
      })
    }else if(val.tel==''){
      wx.showToast({
        title: '请输入患者联系电话',
        icon:"none"
      })
    }else if(val.address==''){
      wx.showToast({
        title: '请输入患者地址',
        icon:"none"
      })
    }else{
      this.setData({
        page_state:2
      })
    }
  },
  // 住院时间选择
  zhuyuantime_choose:function(e){
    console.log(e.detail.value);
    this.setData({
      zhuyuan_text:e.detail.value,
      zy_time:e.detail.value,
    })
  },
  // 出院时间
  chuyuantime_choose:function(e){
    console.log(e.detail.value);
    this.setData({
      chuyuan_text:e.detail.value,
      cy_time:e.detail.value,
    })
  },
  // 科室选择
  keshi_choose:function(e){
    console.log(e)
    var keshiList=this.data.keshiList;
    this.setData({
      keshi_text:keshiList[e.detail.value]
    })
  },
  // 住院号
  zhuyuanhao:function(e){
    console.log(e.detail.value)
    this.setData({
      zhuyuanhao_text:e.detail.value
    })
  },
  // 病症主述
  zhusu:function(e){
    this.setData({
      zhusu_text:e.detail.value
    })
  },
  fucha_choose:function(e){
    this.setData({
      fucha_text:e.detail.value,
      fc_time:e.detail.value
    })
  },
  // 上一步
  prve_page:function(e){
    this.setData({
      page_state:this.data.page_state-1
    })
  },
  // 下一步 到居家康复
  next_jujia:function(e){
    var zhuyuan_text=this.data.zhuyuan_text;
    var chuyuan_text=this.data.chuyuan_text;
    var keshi_text=this.data.keshi_text;
    var zhuyuanhao_text=this.data.zhuyuanhao_text;
    var zhusu_text=this.data.zhusu_text;
    var fucha_text=this.data.fucha_text;
    if(!zhuyuan_text){
      wx.showToast({
        title: '请选择住院时间',
        icon:'none'
      })
    }else if(!chuyuan_text){
      wx.showToast({
        title: '请选择出院时间',
        icon:'none'
      })
    }else if(!fucha_text){
      wx.showToast({
        title: '请选择复查时间',
        icon:'none'
      })
    }else{
      this.setData({
        page_state:this.data.page_state+1
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var back_orser = options.back_orser;
    var j_id = options.j_id;
    var that = this;
    that.setData({
      back_orser:back_orser,
      j_id:j_id,
      zid:options.zid,
      is_zd:options.is_zd
    })
    that.getOrder();

  },
  getOrder:function(e){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/green.baogao_detail",
      data:{
        back_orser:that.data.back_orser,
        j_id:that.data.j_id,
      },
      success:function(res){
        that.setData({
          orderinfo:res.data,
          
        })
        if(res.data.is_zd == 1)
        {
          that.setData({
            zhuyuan_text:res.data.baogao.zy_time,
            chuyuan_text:res.data.baogao.cy_time,
            fucha_text:res.data.baogao.fc_time,
          })
        }
      }
    })
  },
  // 其他检测输入
  other:function(e){
    var that = this;
    that.setData({
      other_content:e.detail.value
    })
  },
  // 保存
  save:function(){
    var that = this;
    var names = that.data.orderinfo.names;
    var sex = that.data.orderinfo.sex;
    var age = that.data.orderinfo.age;
    var address = that.data.orderinfo.city+that.data.orderinfo.xxaddress;
    var zy_time = that.data.zy_time;
    var cy_time = that.data.cy_time;
    var keshi = that.data.orderinfo.keshi;
    var roomid = that.data.orderinfo.roomid;
    var tel =that.data.orderinfo.tel;
    var content = that.data.orderinfo.content;
    var fc_time = that.data.fc_time;
    var xy_am_time = that.data.xy_am_time;
    var xy_am_number = that.data.xy_am_number;
    var xy_pm_time = that.data.xy_pm_time;
    var xy_pm_number = that.data.xy_pm_number;
    var jz_time = that.data.jz_time;
    var xt_am_time = that.data.xt_am_time;
    var xt_am_number = that.data.xt_am_number;
    var xt_pm_time = that.data.xt_pm_time;
    var xt_pm_number = that.data.xt_pm_number;
    var xl_am_time = that.data.xl_am_time;
    var xl_am_number = that.data.xl_am_number;
    var xl_pm_time = that.data.xl_pm_time;
    var xl_pm_number = that.data.xl_pm_number;
    var xb_am_time = that.data.xb_am_time;
    var xb_am_number = that.data.xb_am_number;
    var xb_pm_time = that.data.xb_pm_time;
    var xb_pm_number = that.data.xb_pm_number
    var wb_am_time = that.data.wb_am_time;
    var wb_am_number = that.data.wb_am_number;
    var wb_pm_time = that.data.wb_pm_time;
    var wb_pm_number = that.data.wb_pm_number;
    var ns_am_time = that.data.ns_am_time;
    var ns_am_number = that.data.ns_am_number;
    var ns_pm_time = that.data.ns_pm_time;
    var ns_pm_number = that.data.ns_pm_number;
    var ns_pm_day = that.data.ns_pm_day;
    var sleep_month = that.data.sleep_month
    var sleep_week = that.data.sleep_week;
    var sleep_time = that.data.sleep_time;
    var sleep_number = that.data.sleep_number;
    var tx_month = that.data.tx_month;
    var tx_week = that.data.tx_week;
    var tx_number = that.data.tx_number;
    var am_xt_title = that.data.am_xt_title;
    var pm_xt_title = that.data.pm_xt_title;
    var xy_content = "上午("+xy_am_time+")点("+xy_am_number+")次，下午("+xy_pm_time+")点("+xy_pm_number+")次，测量前静置("+jz_time+")分钟";
    var xt_content = "上午("+xt_am_time+")点("+xt_am_number+")次，"+am_xt_title+"下午("+xt_pm_time+")点("+xt_pm_number+")次，"+pm_xt_title;
    var xl_content = "上午("+xl_am_time+")点("+xl_am_number+")次，下午("+xl_pm_time+")点("+xl_pm_number+")次";
    var xb_content = "上午("+xb_am_time+")点("+xb_am_number+")次，下午("+xb_pm_time+")点("+xb_pm_number+")次";
    var wb_content = "上午("+wb_am_time+")点("+wb_am_number+")次，下午("+wb_pm_time+")点("+wb_pm_number+")次";
    var ns_content = "上午("+ns_am_time+")点("+ns_am_number+")次，下午("+ns_pm_time+")点("+ns_pm_number+")次，（"+ns_pm_day+"周/天）";
    var sleep_content = sleep_month+"月"+sleep_week+" 周"+sleep_time+"天"+sleep_number+" 次；";
    var tx_content = tx_month+"月"+tx_week+" 周"+tx_number+" 次；";
    var other_content = that.data.other_content;
    app.util.request({
      'url':"entryr/wxapp/green.addbaogao",
      data:{
        back_orser:that.data.back_orser,
        openid:wx.getStorageSync('openid'),
        names:names,
        sex:sex,
        age:age,
        tel:tel,
        address:address,
        zy_time:zy_time,
        cy_time:cy_time,
        keshi:keshi,
        roomid:roomid,
        content:content,
        other_content:other_content,
        fc_time:fc_time,
        xy_content:xy_content,
        xt_content:xt_content,
        xl_content:xl_content,
        xb_content:xb_content,
        wb_content:wb_content,
        ns_content:ns_content,
        sleep_content:sleep_content,
        tx_content:tx_content,
        zid:that.data.zid,
        j_id:that.data.j_id
      },
      success:function(res){
        wx.navigateBack({})
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})